import type { RequiredDeep } from 'type-fest'

import { ajax } from '@/utils'

import type { components } from '../schema'

/**
 * 当前用户接口
 */
export const currentUserApi = {
  /**
   * 获取用户信息
   */
  getInfo(): Promise<IGetUserInfoRes> {
    return ajax.get('/current-user/getInfo')
  },
  /**
   * 获取用户配置
   */
  getProfile(): Promise<IGetUserProfileRes> {
    return ajax.get('/current-user/getProfile')
  },
  /**
   * 更新用户基本信息
   */
  updateBase(data: IUpdateUserBaseReq) {
    return ajax.put('/current-user/updateUserBase', data)
  },
  /**
   * 更新用户密码
   */
  updatePassword(data: IUpdateUserPasswordReq) {
    return ajax.put('/current-user/updateUserPassword', data)
  }
}

export type IGetUserInfoRes = RequiredDeep<
  components['schemas']['GetCurrentUserInfoVO']['data']
>
export type IUserMenu = RequiredDeep<
  components['schemas']['CurrentUserInfoVO']['menus']
>
export type IGetUserProfileRes = RequiredDeep<
  components['schemas']['GetCurrentUserProfileVO']['data']
>
export type IUpdateUserBaseReq =
  components['schemas']['UpdateCurrentUserBaseDTO']
export type IUpdateUserPasswordReq =
  components['schemas']['UpdateCurrentUserPasswordDTO']
